// Class

// function Person (name) {
//   this.name = name
// }

// Person.prototype.say = function () {
//   console.log(`hi, my name is ${this.name}`)
// }

// 相比函数实现类的方式class的实现结构更加清晰更容易理解

class Person {
  // 构造函数
  constructor (name) {
    this.name = name
  }

  say () {
    console.log(`hi, my name is ${this.name}`)
  }

  // 静态方法
  static of (name) {
    return new Person(name)
  }
}

const p = new Person('tom')
p.say()

Person.of('jerry').say()


// extends用于实现继承

class Student extends Person {
  constructor (name, number) {
    // super指向父类，调用super即父类构造函数
    super(name)
    this.number = number
  }

  hello () {
    super.say() // 调用父类成员
    console.log(`my school number is ${this.number}`)
  }
}

const s = new Student('jack', '100')
s.hello()
